---
--- Created by tom.
--- DateTime: 2020/12/16 11:05
---
require "Common/fightReport"
require "Common/StoryReport"
require "proto/battle/message/ReqMyTeamInfoMessage"
require "proto/battle/message/ReqBattleReportPathMessage"

--- @class BattlePlaybackManager 战斗回放管理器
BattlePlaybackManager = BattlePlaybackManager or {};
local this = BattlePlaybackManager

local battleRecord;
local ownDungeonBattleRecord;
local battleResult = 0;
local receiveBattleResult = -1
local showBattleResultImmediate = false
local BATTLE_CMD_LIMIT = 1
---是否在loading前收到了战报
local isReceiveReport = false
--- TODO: 缓存设置失效时间
--- @type table 战斗命令缓存
local battleCmdCache = {};
local battleCmdCacheList = {}
local fightType = 0
local isRecode = 0;--回放1 不是回放 0
local battleBackFunc = nil;--战斗结束后的返回页面的方法
local staticSerialId = 0
---多场战斗播放
local multiFightDataList = {}
local multiFightDataListAll = {}
local fightCmdLoadCallback = nil
local firstFight = true;
--- 临时保存最近的战斗记录
--- @param record BattleRecord 战斗记录。可以为空
function BattlePlaybackManager.setBattleRecord(record)
    FightManager.teamRest = {};
    FightManager.battleInfo = {};
    if record.noFight == 1 then
        battleRecord = record;
        log("record noFight = 1")
        return
    end
    local myInfo = record["attacker"];
    local enemyInfo = record["defender"];
    FightManager.teamRest[1] = 1;
    FightManager.teamRest[2] = 2;
    if enemyInfo and tostring(record["defender"]["playerId"]) == tostring(G.serverData["roleInfo"].show.playerId) then
        --    myInfo = record["attacker"];
        --    enemyInfo = record["defender"];
        FightManager.teamRest[1] = 2;
        FightManager.teamRest[2] = 1;
    end
    FightManager.SetHeroSayData(myInfo["formation"][6], clone(myInfo.members), clone(enemyInfo.members))
    FightManager.battleInfo.mySupSkill = myInfo["supportSkillId"];
    FightManager.battleInfo.enemySupSkill = clone(enemyInfo["supportSkillId"]);
    local dataFormation = this.getMembersFormation(enemyInfo["members"], enemyInfo["formation"]);
    local dataMyFormation = this.getMembersFormation(myInfo["members"], myInfo["formation"]);

    if BattlePlaybackManager.GetFightType() == EnumConst.FightTypeConst.RankBattle then
        FightManager.battleInfo.myHelpPartnerModelId = tostring(myInfo["formation"][6]);
        FightManager.battleInfo.enemyHelpPartnerModelId = tostring(enemyInfo["formation"][6]);
    else
        if myInfo["formation"][6] and tostring(myInfo["formation"][6]) ~= "0" then
            FightManager.battleInfo.myHelpManId = clone(myInfo["formation"][6]);
            FightManager.battleInfo.myHelpPartnerModelId = dataMyFormation[6].partnerModelId;
            FightManager.battleInfo.myHelpPartnerSkinId = dataMyFormation[6].useSkinId;
        end
        if enemyInfo["formation"][6] and tostring(enemyInfo["formation"][6]) ~= "0" then
            FightManager.battleInfo.enemyHelpManId = dataFormation[6]["partnerModelId"];
            FightManager.battleInfo.enemyHelpPartnerModelId = dataFormation[6].partnerModelId;
            FightManager.battleInfo.enemyHelpPartnerSkinId = dataFormation[6].useSkinId;
        end
    end
    if BattlePlaybackManager.GetFightType() == EnumConst.FightTypeConst.RankBattle then
        if enemyInfo["formation"][6] and tostring(enemyInfo["formation"][6]) ~= "0" then
            FightManager.battleInfo.enemyHelpManId = tonumber(tostring(enemyInfo["formation"][6]));
        end
    end

    if dataFormation[4]["partnerModelId"] and tonumber(tostring(dataFormation[4]["partnerModelId"])) > 9000 then
        local bossId = tostring(dataFormation[4]["partnerModelId"]);
        FightManager.battleInfo.bossId = bossId;
        if BattlePlaybackManager.GetFightType() == EnumConst.FightTypeConst.TRIAL then
            FightManager.battleInfo.trialId = TrialsManager.GetBossConfigById(bossId)["f_Trials"]
        end
    end
    battleRecord = record;
end

--- 获取临时保存的战斗结果
--- @return number 最近的战斗结果
function BattlePlaybackManager.getBattleResult()
    return battleResult;
end
--获取对方专武品质
function BattlePlaybackManager.GetWeaponRankByModelId(modeId)
    if battleRecord then
        local enemyInfo = battleRecord["defender"]["members"];
        for _, v in pairs(enemyInfo) do
            if v.partnerModelId == modeId then
                return v.weaponRank
            end
        end
    end
    return 1
end

--- 临时保存最近的战斗结果
--- @param result number 战斗结果。可以为空
function BattlePlaybackManager.setBattleResult(result)
    receiveBattleResult = result
    battleResult = result;
end
function BattlePlaybackManager.IsReceiveResult()
    return receiveBattleResult ~= -1
end
function BattlePlaybackManager.ClearReceiveResult()
    receiveBattleResult = -1
    showBattleResultImmediate = false
end
function BattlePlaybackManager.IsShowBattleResultImmediate()
    return showBattleResultImmediate
end
function BattlePlaybackManager.SetShowBattleResultImmediate(show)
    showBattleResultImmediate = show
end
--- 获取临时保存的战斗数据
--- @return BattleRecord 最近的战斗数据
function BattlePlaybackManager.getBattleRecord()
    return battleRecord;
end

function BattlePlaybackManager.ContainsPartner(partnerId)
    for i, v in pairs(battleRecord.attacker.members) do
        if tostring(v.partnerId) == tostring(partnerId) then
            return true
        end
    end
    return false
end
--- 临时保存自己主线的战斗数据
function BattlePlaybackManager.setOwnDungeonBattleRecord(record)
    ownDungeonBattleRecord = record;
end
--- 获取自己主线临时保存的战斗数据
--- 主线可以播放其他战报会导致战报混乱
function BattlePlaybackManager.getOwnDungeonBattleRecord()
    return ownDungeonBattleRecord;
end

function BattlePlaybackManager.IsReceiveReport()
    return isReceiveReport
end
function BattlePlaybackManager.ResetReceiveReport()
    isReceiveReport = false
end

function BattlePlaybackManager.GetIsRecord()
    return isRecode;
end

function BattlePlaybackManager.GetFightType()
    return fightType
end
function BattlePlaybackManager.SetFightType(type)
    fightType = type
end

local formation_type = nil
function BattlePlaybackManager.GetFormationType()
    return formation_type
end
function BattlePlaybackManager.SetFormationType(_formation_type)
    formation_type = _formation_type
end

function BattlePlaybackManager.GetFightIndex()
    return this.fightIndex == nil and 1 or this.fightIndex;
end

--剧情模式数据临时存储
function BattlePlaybackManager.SetHardDungeonData(data,record)
    this.hardDatas[data] = record
end

function BattlePlaybackManager.GetHardDungeonData()
    return this.hardDatas
end

function BattlePlaybackManager.ClearHardDungeonData()
    this.hardDatas = nil
end

------------------- 多队推图处理 -----------开始------------------
-- 临时储存主线多队推图数据,退出布阵界面是清空
function BattlePlaybackManager.SetGroupBossHistory(data)
    this.groupBossHistoryList = data;
    if data == nil or #data == 0 then
        this.SetGroupBossNowGroupId();
        this.SetGroupBossIsOver();
    end
end
function BattlePlaybackManager.UpdateGroupBossHistory(data)
    if this.groupBossHistoryList == nil then
        this.groupBossHistoryList = {};
    end
    this.groupBossHistoryList[data.groupId] = data;
end
function BattlePlaybackManager.GetGroupBossHistory(groupId)
    if this.groupBossHistoryList == nil then
        this.groupBossHistoryList = {};
    end
    if groupId == nil then
        return this.groupBossHistoryList;
    end
    return this.groupBossHistoryList[groupId];
end

function BattlePlaybackManager.SetGroupBossNowGroupId(index)
    if index and index <= 0 then
        return ;
    end
    this.GroupBossNowGroupId = index;
end
function BattlePlaybackManager.GetGroupBossNowGroupId()
    return this.GroupBossNowGroupId or 1;
end
function BattlePlaybackManager.SetGroupBossIsOver(flag)
    this.GroupBossIsOver = flag;
end
function BattlePlaybackManager.GetGroupBossIsOver()
    return this.GroupBossIsOver;
end
function BattlePlaybackManager.GetGroupBossJoinGroupId(fightType)
    local index = this.GetGroupBossNowGroupId();
    local data = this.GetGroupBossHistory(index);
    if data == nil or data.record == nil or data.record.win == 0 then
        return index;
    end
    local teamNum = logicMgr.MapManager.getStageNeedTeamNum();
    if fightType == EnumConst.FightTypeConst.StoryBattle then
        teamNum = logicMgr.MapManager.getStoryBattleNeedTeamNum()
    end
    for i = 1, teamNum do
        data = this.GetGroupBossHistory(i);
        if data == nil or data.record == nil or data.record.win == 0 then
            return i;
        end
    end
    return 1, true;
end

------------------- 多队推图处理 ------结束-----------------------
--- 请求战斗命令, 成功后播放战斗回放
--- @param record BattleRecord 战斗记录
--- @param fightType number 战斗类型
--- @param onPlayBegin function 回放开始回调
--- @param onPlayFinished function 回放结束回调
--- @param cancelFunc function 是否取消播放
function BattlePlaybackManager.requestFightCmdThenPlay(record, _fightType, onPlayBegin, onPlayFinished, cancelFunc)
    BattlePlaybackManager.requestFightCmd(record, _fightType, function(fightCmdList)
        local battleInfo = {}

        if cancelFunc ~= nil and cancelFunc() then
            return
        end
        fightType = _fightType;
        if fightCmdList ~= nil then
            BattlePlaybackManager.playBattle(fightCmdList, fightType, onPlayBegin, onPlayFinished, battleInfo);
        else
            UISysTips.AddMsg(getLanguage("Character_Tips25"));
        end
    end);
end
this.isWaiting = false;
--- 请求战斗命令
--- @param record BattleRecord 战斗记录
--- @param _fightType number 战斗类型
--- @param onLoaded function 战斗命令请求返回
---@private
function BattlePlaybackManager.requestFightCmd(record, _fightType, onLoaded)
    isRecode = 1;
    --- 转成string类型，cjson解析long会截断到14位
    fightType = _fightType
    FightManager.fightType = _fightType
    local fightId = tostring(record.fightId);
    local fightReportPath = tostring(record.fightReportPath);
    this.FightId = tostring(fightId)
    --if battleCmdCache[fightId] ~= nil then
    --        onLoaded(battleCmdCache[fightId]);
    --    return
    --end
    fightCmdLoadCallback = onLoaded
    log("requestFightCmd:"..fightReportPath)
    if record.oss == 1 or record.ossDev == 1 then
        dungeonHandler.ReqBattleReportPathMessage(fightId,fightReportPath)
    else
        local url = logicMgr.LoginManager.GetHttpServerUrl() .. "fight/"
        url = url .. fightReportPath .. ".bt"
        BattlePlaybackManager.ResBattleReportPath(url)
    end

    --[[local url
    if record.oss == 1 then
        --url = "http://fszx-oss.oss-cn-shanghai.aliyuncs.com/fight/"
        --if Config.DefaultServerId == 0 then
        --url = Config.FORMAL_FIGHT_URL..AppConst.ServerId.."/"
        url = Config.FORMAL_FIGHT_URL
        --end
    else
        if record.ossDev == 1 then
            url = "http://fszx-oss.oss-cn-shanghai.aliyuncs.com/fight/"

        else
            url = logicMgr.LoginManager.GetHttpServerUrl() .. "fight/"
        end
    end
    url = url .. fightReportPath .. ".bt"

    Http.httpReqTimeOut = 5
    if not this.isWaiting then
        log("战报url===" .. url)
        this.isWaiting = true;
        Http.Get(url, nil, function(success, cmdStr)
            Http.httpReqTimeOut = 0
            if not success then
                logError("http get fight cmd failed. url: " .. url .. ". ErrMsg: " .. cmdStr)
                this.isWaiting = false;
                --onLoaded(nil)
                logicMgr.BattlePlaybackManager.SetShowBattleResultImmediate(true)
                this.CancelRepeatRequest();
                ArenaManager.setSomeBattleSkip(true)
                DestoryUI(PanelNames.UILoadingBattle);
                FightManager.showResultUI(true);
                --UISysTips.AddMsg("请求战报失败")
                return
            end
            local fightCmdList = decodeJsonStrToTabel(decodeJsonStrToTabel(cmdStr));
            if fightCmdList == nil or (fightCmdList.code ~= nil and fightCmdList.code ~= 0) then
                logError("decode fight cmdStr failed: " .. (cmdStr or ""));
                onLoaded(nil)
                return
            end
            if FightManager.hasEntrance then
                --如果进入战斗了则返回
                return ;
            end

            log("http get fight cmd success url: " .. url)
            onLoaded(fightCmdList)
            this.isWaiting = false;
        end);
    end]]
end
function BattlePlaybackManager.ResBattleReportPath(fullPath)
    local url = fullPath
    Http.httpReqTimeOut = 5
    if not this.isWaiting then
        log("战报url===" .. url)
        this.isWaiting = true;
        Http.Get(url, nil, function(success, cmdStr)
            Http.httpReqTimeOut = 0
            if not success then
                logError("http get fight cmd failed. url: " .. url .. ". ErrMsg: " .. cmdStr)
                this.isWaiting = false;
                --onLoaded(nil)
                logicMgr.BattlePlaybackManager.SetShowBattleResultImmediate(true)
                this.CancelRepeatRequest();
                ArenaManager.setSomeBattleSkip(true)
                DestoryUI(PanelNames.UILoadingBattle);
                FightManager.showResultUI(true);
                UISysTips.AddMsg(getLanguage("ErrorCode_220004"))
                return
            end
            local fightCmdList = decodeJsonStrToTabel(decodeJsonStrToTabel(cmdStr));
            if fightCmdList == nil or (fightCmdList.code ~= nil and fightCmdList.code ~= 0) then
                logError("decode fight cmdStr failed: " .. (cmdStr or ""));
                if fightCmdLoadCallback then
                    fightCmdLoadCallback(nil)
                end
                return
            end
            if FightManager.hasEntrance then
                --如果进入战斗了则返回
                return ;
            end

            log("http get fight cmd success")
            if fightCmdLoadCallback then
                fightCmdLoadCallback(fightCmdList)
            end
            this.isWaiting = false;
        end);
    end
end
--- 播放战斗回放
--- @param fightCmdList table 战斗命令字符串
--- @param _fightType number 战斗类型
--- @param onPlayBegin function 回放开始回调
--- @param onPlayFinished function 回放结束回调
function BattlePlaybackManager.playBattle(fightCmdList, _fightType, onPlayBegin, onPlayFinished)
    if FightManager.hasInit then
        FightManager.stopCommand();
        FightManager.destroy();
    end
    this.cur_play_fight_type = _fightType

    FightManager.init();
    FightManager.readReport(fightCmdList, _fightType, battleResult);

    BattleScene.pause();
    BattleScene.destroyScene();

    if onPlayBegin then
        onPlayBegin()
    end

    showUI(PanelNames.UILoadingBattle, FightManager.resList, function()
        utimer.delayCall(function()
            DestoryUI(PanelNames.UILoadingBattle);
            showUI(PanelNames.UIBattleMain, function()
                --closeUI(PanelResNames.UIHeadMenu);
                --UIBottom.enterAdventure();
                if onPlayFinished then
                    onPlayFinished()
                end
            end, battleInfo)
            FightManager.entrance();
        end, 500)
    end);
end

function BattlePlaybackManager.handlerMyTeamInfo(msg)
    local teamFormation = {}
    for i, v in ipairs(msg.teams) do
 local formation = decodeJsonStrToTabel(v.teamInfo)
        table.insert(teamFormation,formation)
    end
    this.formationCallBackFunc(teamFormation)
end

function BattlePlaybackManager.reqClientBattle(callback,failCallBack)
    --local req = ReqBattleReportPathMessage.New()
    --req.id =id
    --battleInfo
    local param = {}
    for i, v in pairs(ClientFight.FightController.batchBattleResult) do
            v.class = nil;
        param["fightId"] = v.fightId;
        v.fightId = nil;
        for i1, v1 in pairs(v.atkMemberStats) do
            v1.class = nil;
            v.atkMemberStats[tostring(i1)]= v1;
            v.atkMemberStats[i1] = nil;
        end
    end
    param["batchBattleResult"] = ClientFight.FightController.batchBattleResult;
    param["battleReports"] = ClientFight.FightController.battleReports;

    local str = getJsonStr(param);
    local url = logicMgr.LoginManager.GetHttpServerUrl1()..G.serverData['webPort'].."/battleUpload/"
    printError(url)

    local headers = {["Content-type"] = "application/json;charset=utf-8"}
    if AppConst.UserToken then
        headers["Authorization"] = AppConst.UserToken
    end
    Http.Post(url, str, function(success, data)
        if success then
            printError(data)
            callback( param["fightId"])
        else
            printError("fail====="..data)
            failCallBack()
        end
    end, headers)
    --WebMsgMgr:SendHttpRequest(url,str);

end

function BattlePlaybackManager.getClientBattleFormation(cb,formationInfo,fightType, param)
     local req = ReqMyTeamInfoMessage.New()
    req.atkFormation = formationInfo;
    req.assistantSkillType = fightType;
    sendReqMessage(req);
    this.formationCallBackFunc = cb;

end

function BattlePlaybackManager.playClientBattle( _fightType, onPlayBegin, onPlayFinished)
    FightSelect.isShowSaveReport = true;
    if FightManager.hasInit then
        FightManager.stopCommand();
        FightManager.destroy();
    end
    this.cur_play_fight_type = _fightType
    FightManager.fightType = _fightType

    FightManager.init();
    FightManager.readReport(nil, _fightType, battleResult);

    BattleScene.pause();
    BattleScene.destroyScene();

    if onPlayBegin then
        onPlayBegin()
    end

    showUI(PanelNames.UILoadingBattle, FightManager.resList, function()
        utimer.delayCall(function()
            DestoryUI(PanelNames.UILoadingBattle);
            showUI(PanelNames.UIBattleMain, function()
                --closeUI(PanelResNames.UIHeadMenu);
                --UIBottom.enterAdventure();
                if onPlayFinished then
                    onPlayFinished()
                end
            end, battleInfo)
            FightManager.entrance();
        end, 500)
    end);
end

function BattlePlaybackManager.AddMultiFightData(fightId, fightResult, _fightType, record, items, teamType, enemyTeamId)
    local data = { fightId = fightId, --战斗id
                   fightResult = fightResult, --战斗返回
                   fightType = _fightType, --战斗类型
                   record = record,
                   items = items,
                   teamId = teamType, --我方该场战斗出战的队伍
                   enemyTeamId = enemyTeamId --敌方该场战斗出战的队伍
    };
    table.insert(multiFightDataList, data);
    table.insert(multiFightDataListAll, data);
end
function BattlePlaybackManager.ClearMultiFightData()
    table.clear(multiFightDataListAll);
    table.clear(multiFightDataList)
    this.fightIndex = 0
    logicMgr.MythicDungeonsProManager.ClearShowList()
end
function BattlePlaybackManager.HasNextFight()
    return #multiFightDataList > 0
end
function BattlePlaybackManager.GetMultiData()
    return multiFightDataList[1]
end

function BattlePlaybackManager.GetMultiDataAll()
    return multiFightDataListAll[this.fightIndex]
end
function BattlePlaybackManager.GotoNextFight(needPlay)
    if #multiFightDataList == 0 then
        logError("没有下一场战斗鸟")
        return
    end

    this.fightIndex = this.fightIndex + 1
    local data = table.remove(multiFightDataList, 1)
    fightType = data.fightType
    if needPlay then
        BattlePlaybackManager.setBattleRecord(data.record)
        BattlePlaybackManager.setBattleResult(data.fightResult)
        FightManager.InitRewards(data.items)
        BattlePlaybackManager.requestFightCmdThenPlay(data.record, data.fightType)
    else
        FightManager.InitRewards(data.items)
        BattlePlaybackManager.RequestReport(data.fightId, data.fightResult, data.record)
    end
end
--region 1、发送请求,同时预载资源  2、loading等待  3、收到请求loading结束
--预先进入战斗
function BattlePlaybackManager.GotoFight(_fightType)
    --播放音效
    --playCommonByType(Config.SoundType.ST_UI_battle_boss);
    BattleScene.pause();
    BattleScene.destroyScene();
    if FightManager.hasInit then
        FightManager.stopCommand();
        FightManager.destroy();
    end
    fightType = _fightType

    if ItemFlyMgr ~= nil then
        ItemFlyMgr.OnDestroy()
    end

    showUI(PanelNames.UILoadingBattle, FightManager.resList, function()
        if firstFight then
            --firstFight = false
            FightManager.PreEntrance()
             utimer.delayCall(function()
                 DestoryUI(PanelNames.UILoadingBattle);
                 hideOtherUI(true);
                 showUI(PanelNames.UIBattleMain, nil, battleInfo);
        
                 FightManager.PreEntranceLoadingFinished()
             end, 1000);
        else
            DestoryUI(PanelNames.UILoadingBattle);
            hideOtherUI(true);
            showUI(PanelNames.UIBattleMain, nil, battleInfo);
            FightManager.entrance()
        end
    end, true);

    utimer.delayCall(function ()
        BattleSceneCacheResouce:PrepareLoadRes()
        FightManager.UpdateResTime()
        HelperFunc.UnloadUnusedAssets(EnumConst.ClearType.Fight)
        --HelperFunc.UnloadBattleRes()
        UICity.removeMyPetModel()
    end, 1)
end
function BattlePlaybackManager.RequestReport(fightId, fightResult, record)
    if this.isRequestReport then
        log("wait report")
        return
    end
    this.FightId = fightId
    this.setBattleRecord(record)
    this.setBattleResult(fightResult)
    this.isRequestReport = true
    this.requestTimes = 0
    this.DoRequestReport()
    this.requestTimerId = utimer.timeCall(this.DoRequestReport, 4000, -1)
end
function BattlePlaybackManager.DoRequestReport()
    if this.requestTimes > 1 then
        logError("正在重新请求，请稍后...count:" .. this.requestTimes)
    end
    this.requestFightCmd(battleRecord, fightType, function(fightCmdList)
        this.requestTimes = this.requestTimes + 1
        if isReceiveReport then
            return
        end
        this.CancelRepeatRequest()
        if fightCmdList == nil then
            printError("进入战斗错误-战斗命令请求失败:" .. tostring(battleRecord.fightId));
            --FireEvent(Config.EventType.LoadingCancelByFightError, "战斗命令请求失败")
            ArenaManager.setSomeBattleSkip(true)
            DestoryUI(PanelNames.UILoadingBattle);
            FightManager.showResultUI(true);

            return
        end
        isRecode = 0;
        FightManager.saveBattleReport(fightCmdList);
        FightManager.init();
        isReceiveReport = true
        FightManager.readReport(fightCmdList, fightType, this.getBattleResult());
    end)
end
function BattlePlaybackManager.CancelRepeatRequest()
    this.isRequestReport = false
    utimer.remove(this.requestTimerId)
    this.requestTimerId = nil
end
--endregion 1、发送请求同时预载资源  2、loading等待  3、接受请求loading结束
function BattlePlaybackManager.getMembersFormation(members, formations)
    local formation = {};
    for i = 1, 6 do
        formation[i] = {};
        for k, v in pairs(members) do
            if tostring(v.partnerId) == tostring(formations[i]) then
                formation[i] = v;
                break ;
            end
        end
    end
    return formation;
end
--战斗结束后返回的UI执行方法
function BattlePlaybackManager.setBattleBackFunc(func)
    battleBackFunc = func;
end
--调用战斗结束后返回的UI执行方法
function BattlePlaybackManager.doBattleBackFunc(func)
    if func then
        func();
        return ;
    end
    if battleBackFunc then
        battleBackFunc();
    end
end

function BattlePlaybackManager.playReport(id,type)
    --log(filepath);
    local report = nil
    --log(report);
    if FightManager.hasInit then
        FightManager.stopCommand();
        FightManager.destroy();
    end
    if type then
        fightType = EnumConst.FightTypeConst.PerformBattle
        report = StoryReport[tonumber(101)]
    else
        fightType = EnumConst.FightTypeConst.DUNGEON
        report = fightReport[tonumber(id)]
    end
    BattleScene.pause();
    BattleScene.destroyScene();

    BattlePlaybackManager.setBattleResult(1)
    local fightreport = decodeJsonStrToTabel(report);
    FightManager.saveBattleReport(fightreport);
    FightManager.init();
    FightManager.readReport(fightreport, fightType, 1);
    showUI(PanelNames.UILoadingBattle, FightManager.resList, function()
        utimer.delayCall(function()
            DestoryUI(PanelNames.UILoadingBattle);
            showUI(PanelNames.UIBattleMain, function()
                --closeUI(PanelResNames.UIHeadMenu);
                --UIBottom.enterAdventure();
            end, battleInfo)
            FightManager.entrance();
        end, 500);
    end);
end
return BattlePlaybackManager;